
#include <promote/StopWatch.hpp>
#include <promote/Timestamp.hpp>
#include <promote/TimeUtils.hpp>

#include "BlackScholes.hpp"
#include "BlackScholesTest.hpp"
#include "ExpiryCalculator.hpp"
#include "VanillaOption.hpp"

using namespace provident;
using namespace provident::test;

//static double perfTestAmericanCall(int const height);
static double perfTestEuropeanCall();

void provident::test::unitTestBlackScholes()
{
}

void provident::test::perfTestBlackScholes()
{
    //for(int ii = 25; ii <= 200; ii += 25) {
        printf("european call: %g ns\n", perfTestEuropeanCall());
    //}
    //for(int ii = 25; ii <= 200; ii += 25) {
    //    printf("european call (height=%d): %g ns\n", ii, perfTestEuropeanCall(ii));
    //}
}

static double perfTestEuropeanCall()
{
    std::size_t const iters(1000000);
    promote::StopWatch stopWatch;
    promote::Timestamp timestamp;
    timestamp.dayOfMonth(150);
    ExpiryCalculator calc(ExpiryCalculator::CALENDAR_YEAR);
    VanillaOption option(promote::String("AAPL OPTION NAME",false),
                         promote::String("AAPL",false),
                         calc.yearsTilExpiry(timestamp), 
                         200, VanillaOption::CALL,
                         VanillaOption::EUROPEAN);

    BlackScholes bs;
    stopWatch.start();
    for(std::size_t iter = 0; iter != iters; ++iter) {
        bs.valuate(option, 225.0, 0.5, 0.25); 
    }
    stopWatch.stop();

    return (promote::getTimevalAsMicros(stopWatch.elapsed())) * 1000.0 / iters;
}

